package com.xinqi.modules.course.course.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.course.client.RemoteCourseClient;
import com.xinqi.modules.course.course.dto.rsp.CourseResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 课程服务 -- 熔断降级处理
 *
 * @Author：yyzhen
 * @Package：com.xinqi.modules.course.course.course.factory
 * @Project：xingqiclass-cloud-plus
 * @name：RemoteCourseFallbackFactory
 * @Date：2023/3/10 11:29
 * @Filename：RemoteCourseFallbackFactory
 */
@Slf4j
@Component
public class RemoteCourseFallbackFactory implements FallbackFactory<RemoteCourseClient> {


    @Override
    public RemoteCourseClient create(Throwable cause) {
        log.error("课程服务调用失败:{}", cause.getMessage());
        return new RemoteCourseClient() {

            @Override
            public R<CourseResultDTO> findCourse(Long courseId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> accountCancel(Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> initDemonstrate(Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

        };
    }


}
